<?php
class upload_admin extends controller {
	function index() {

		if(isset($_FILES["images"]) ){
	        $name = $_POST["name"];
			$tempName=preg_replace("/-[0-9]{1,3}.jpg$/i", '',  $name);
			
			$image = new upload_resize;
			$image->load( $_FILES["images"]["tmp_name"]);
			$image->resizeToHeight(1000);
			if(file_exists(FCPATH."images/$name"))
				foreach(range(1,20) as $i){
					$name = $tempName."-$i.jpg";
					if(!file_exists(FCPATH."images/$name"))break;
				}
			$image->save(FCPATH."images/$name");
			$image->resizeToHeight(200);
			$image->save(FCPATH."images/thumbnails/$name");
			//$outImg="{$url_site}images/thumbnails/$name";
			$_SESSION['PhotoName'][]=$name;
			unlink( $_FILES["images"]["tmp_name"]);
		}
		
	}
}